'''
Created on Jun 7, 2011

@author: stelios
'''
html_escape_table = {
       "&": "&amp;",
        '"': "&quot;",
        "'": "&apos;",
        ">": "&gt;",
        "<": "&lt;",
        }
    
def escape(text):
    """Produce entities within text."""
    return "".join(html_escape_table.get(c,c) for c in text)

def unescape(s):
    s = s.replace("&lt;", "<")
    s = s.replace("&gt;", ">")
    # this has to be last:
    s = s.replace("&amp;", "&")
    return s